from django.db import models

# Create your models here.
from myutiles.base_model import BaseModel

"""
省市县镇
"""
class Cate(BaseModel):
    """
    商品分类
    """
    cate_name = models.CharField(max_length=30)  # 分类名称
    cid = models.ForeignKey('self',on_delete=models.CASCADE,null=True,blank=True)

    class Meta:
        db_table = 'cate'

    def __str__(self):
        return self.cate_name




class Goods(BaseModel):
    """
    商品信息
    """
    goods_name = models.CharField(max_length=80)
    goods_price = models.DecimalField(max_digits=8,decimal_places=2)
    color = models.ManyToManyField('Color')
    version = models.ManyToManyField('Version')  # 版本
    detail = models.TextField()  # 详情
    spen = models.CharField(max_length=10) # 规格
    goods_img = models.ImageField(upload_to='goods',null=True,blank=True)  # 图片yt
    cate = models.ForeignKey(Cate,on_delete=models.CASCADE,null=True,blank=True)
    class Meta:
        db_table = 'goods'

    def __str__(self):
        return self.goods_name


class Color(BaseModel):
    """
    颜色
    """
    color_name = models.CharField(max_length=500)

    class Meta:
        db_table = 'color'



    def __str__(self):
        return self.color_name



class Version(BaseModel):
    """
    版本
    """
    version_name = models.CharField(max_length=500)

    class Meta:
        db_table = 'version'

    def __str__(self):
        return self.version_name


